<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>设置付款方式</title>
<meta name="decorator" content="default" />
<style type="text/css">

</style>
<script type="text/javascript">
	var cardAllID;
	var cardAllName;
	var cardAllNum;
	var cardAllMoney;
	$(document).ready(function() {
		registerSelectListener("contentTableAllCards");
	});
	function registerSelectListener(target) {
		var trs = "#" + target + " tbody tr";
		$(trs).click(function() {
			$("#" + target + " tbody tr").removeClass("select_active");
			$(this).addClass("select_active");
			if('contentTableAllCards'==target){
				cardAllID = $(this).attr("id");
				cardAllName = $(this).find("#name").text();
				cardAllMoney = $(this).find("#money").text();
			    cardAllNum = $(this).find("#num").text();
			} 
		});

		var currentId = '${contentTableAllCards}';
		if (currentId == '') {
			$("#" + target + " tbody tr:first-child").click();
		} else {
			$("#" + currentId).click();
		}
	}
	 

	function paybyCardAll() {
		if (cardAllID == null || cardAllName == null) {
			alert("请先选择综合充值卡支付");
			return false;
		}
		$("#allcardId").val(cardAllID);
		alert("您选择使用综合充值卡【" + cardAllName+"】支付 "+$("#cashMoney").val()+"元 ,请确认支付信息是否正确？");
		return true;
	}
 

	function page(n, s) {
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
		return false;
	}
</script>

</head>
<body>
<div class="controls controls-row">
		<a href="${ctx}/cash/member/detail?id=${member.customer.id}"><button
				class="btn btn-primary span3">返回</button></a> <br /> <br />
	</div>
	<tags:message content="${message}" />
	<div>
		<h3 id="myModalLabel">设置付款方式</h3>
		<div class="modal-body">
			<p>确认已添加支付</p>
			<strong>应付金额：${member.rechargeEleMgr.payment.totalCost} 元</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<strong>已确认付款金额：${member.rechargeEleMgr.payment.alreadyPaid} 元</strong>
			&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<strong>未确认付款金额：${member.rechargeEleMgr.payment.leftToPay}
				元</strong>&nbsp;&nbsp;&nbsp;&nbsp;
			<table class="table table-striped table-bordered ">
				<thead>
					<tr>
						<th colspan="2">现金支付</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>支付金额</td>
						<td>${member.rechargeEleMgr.payment.cash}</td>
					</tr>
				</tbody>
			</table>
			<table class="table table-striped table-bordered ">
				<thead>
					<tr>
						<th colspan="5">综合充值卡支付</th>
					</tr>
					<tr>
						<th>卡名</th>
						<th>卡号</th>
						<th>当前余额</th>
						<th>支付金额</th>
						<th>支付后余额</th>
					</tr>
				</thead>
				<tbody>
						<c:forEach items="${member.rechargeEleMgr.payment.cardsPaymentDetails}"
							var="detail">
						<tr>
							<th>${detail.cardPayment.card.template.name}</th>
							<th>${detail.cardPayment.card.cardNumber}</th>
							<th>${detail.currentLeftMoney}</th>
							<th>${detail.cardPayment.money}</th>
							<th>${detail.currentLeftMoney-detail.money}</th>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
		<div>
			<ul class="nav nav-tabs" id="myTab">
				<li class="${tabActive.id==0?'active':'' }"><a
					href="#payByAllCard" data-toggle="tab">现金卡充值支付</a></li>
				<li class="${tabActive.id==1?'active':'' }"><a
					href="#payByCash" data-toggle="tab">现金支付</a></li>
			</ul>
		</div>
		<div class="tab-content">
			<div class="tab-pane ${tabActive.id==0 ?'active':'' }"
				id="payByAllCard">
				<form
					action="${ctx}/cash/member/payway/recharge/allcard?id=${member.customer.id}"
					method="post">
					<input type="hidden" id="allcardId" name="allcardId" />
					<div class="controls">
						当前选中【<label id="currentCardName"></label>】
						<div class="input-prepend input-append">
							<label><strong>支付 金额</strong></label> <span class="add-on">￥</span>
							<input class="span2" id="cashMoney" type="text" name="cashMoney"
								value="${member.rechargeEleMgr.payment.leftToPay}" /><span
								class="add-on">元</span>
						</div>
						<button type="submit" onclick="return paybyCardAll()">确认支付方式</button>
					</div>

				</form>
				<table id="contentTableAllCards" class="table table-striped table-bordered ">
					<thead>
						<tr>
							<th colspan="5">综合充值卡支付</th>
						</tr>
						<tr>
							<th>卡名</th>
							<th>卡号</th>
							<th>当前余额</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${member.avaibleAllCards}"
							var="card">
							<tr id="${card.card.id}">
								<td id="name">${card.card.template.name}</td>
								<td id="num">${card.card.cardNumber}</td>
								<td id="money">${card.card.money-card.money}</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<div class="tab-pane  ${tabActive.id==1 ?'active':''}" id="payByCash">
				<form
					action="${ctx}/cash/member/payway/recharge/cash?id=${member.customer.id}"
					method="post">
					<div class="controls">
						<label><strong>现金支付 </strong></label>
						<div class="input-prepend input-append">
							<span class="add-on">￥</span> <input class="span2" id="cashMoney"
								type="text" name="cashMoney"
								value="${member.rechargeEleMgr.payment.leftToPay}" /><span
								class="add-on">元</span>
						</div>
						<button type="submit">确认支付方式</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
</html>
